home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / wrapper / daemon.sh next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2012-04-01  |  41.0 KB  |  1,275 lines

  1. #! /bin/sh
  2.  
  3. #
  4. # Copyright (c) 1999, 2010 Tanuki Software, Ltd.
  5. # http://www.tanukisoftware.com
  6. # All rights reserved.
  7. #
  8. # This software is the proprietary information of Tanuki Software.
  9. # You shall use it only in accordance with the terms of the
  10. # license agreement you entered into with Tanuki Software.
  11. # http://wrapper.tanukisoftware.com/doc/english/licenseOverview.html
  12. #
  13. # Java Service Wrapper sh script.  Suitable for starting and stopping
  14. #  wrapped Java applications on UNIX platforms.
  15. #
  16.  
  17. #-----------------------------------------------------------------------------
  18.  
  19. if [ -z "$WRAPPER_CONF" ]; then
  20.     echo >&2 "WRAPPER_CONF not set; abort"
  21.     exit 1
  22. fi
  23.  
  24. #-----------------------------------------------------------------------------
  25.  
  26. # Required for HP-UX Startup
  27. if [ `uname -s` = "HP-UX" -o `uname -s` = "HP-UX64" ] ; then
  28.         PATH=$PATH:/usr/bin
  29. fi
  30.  
  31. # Get the fully qualified path to the script
  32. case $0 in
  33.     /*)
  34.         SCRIPT="$0"
  35.         ;;
  36.     *)
  37.         PWD=`pwd`
  38.         SCRIPT="$PWD/$0"
  39.         ;;
  40. esac
  41.  
  42. # Resolve the true real path without any sym links.
  43. CHANGED=true
  44. while [ "X$CHANGED" != "X" ]
  45. do
  46.     # Change spaces to ":" so the tokens can be parsed.
  47.     SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
  48.     # Get the real path to this script, resolving any symbolic links
  49.     TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
  50.     REALPATH=
  51.     for C in $TOKENS; do
  52.         # Change any ":" in the token back to a space.
  53.         C=`echo $C | sed -e 's;:; ;g'`
  54.         REALPATH="$REALPATH/$C"
  55.         # If REALPATH is a sym link, resolve it.  Loop for nested links.
  56.         while [ -h "$REALPATH" ] ; do
  57.             LS="`ls -ld "$REALPATH"`"
  58.             LINK="`expr "$LS" : '.*-> \(.*\)$'`"
  59.             if expr "$LINK" : '/.*' > /dev/null; then
  60.                 # LINK is absolute.
  61.                 REALPATH="$LINK"
  62.             else
  63.                 # LINK is relative.
  64.                 REALPATH="`dirname "$REALPATH"`""/$LINK"
  65.             fi
  66.         done
  67.     done
  68.  
  69.     if [ "$REALPATH" = "$SCRIPT" ]
  70.     then
  71.         CHANGED=""
  72.     else
  73.         SCRIPT="$REALPATH"
  74.     fi
  75. done
  76.  
  77. # Change the current directory to the location of the script
  78. cd "`dirname "$REALPATH"`"
  79. REALDIR=`pwd`
  80.  
  81. # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
  82. #  the working directory is later changed.
  83. FIRST_CHAR=`echo $PIDDIR | cut -c1,1`
  84. if [ "$FIRST_CHAR" != "/" ]
  85. then
  86.     PIDDIR=$REALDIR/$PIDDIR
  87. fi
  88. # Same test for WRAPPER_CMD
  89. FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
  90. if [ "$FIRST_CHAR" != "/" ]
  91. then
  92.     WRAPPER_CMD=$REALDIR/$WRAPPER_CMD
  93. fi
  94. # Same test for WRAPPER_CONF
  95. FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1`
  96. if [ "$FIRST_CHAR" != "/" ]
  97. then
  98.     WRAPPER_CONF=$REALDIR/$WRAPPER_CONF
  99. fi
  100.  
  101. # Process ID
  102. ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
  103. STATUSFILE="$PIDDIR/$APP_NAME.status"
  104. JAVASTATUSFILE="$PIDDIR/$APP_NAME.java.status"
  105. PIDFILE="$PIDDIR/$APP_NAME.pid"
  106. LOCKDIR="/var/lock/subsys"
  107. LOCKFILE="$LOCKDIR/$APP_NAME"
  108. pid=""
  109.  
  110. # Resolve the location of the 'ps' command
  111. PSEXE="/usr/ucb/ps"
  112.     if [ ! -x "$PSEXE" ]
  113.     then
  114.         PSEXE="/usr/bin/ps"
  115.         if [ ! -x "$PSEXE" ]
  116.         then
  117.             PSEXE="/bin/ps"
  118.             if [ ! -x "$PSEXE" ]
  119.             then
  120.                 eval echo  'Unable to locate "ps".'
  121.                 eval echo  'Please report this message along with the location of the command on your system.'
  122.                 exit 1
  123.             fi
  124.         fi
  125.     fi
  126.  
  127. # Resolve the os
  128. DIST_OS=`uname -s | tr [A-Z] [a-z] | tr -d ' '`
  129. case "$DIST_OS" in
  130.     'sunos')
  131.         DIST_OS="solaris"
  132.         ;;
  133.     'hp-ux' | 'hp-ux64')
  134.         # HP-UX needs the XPG4 version of ps (for -o args)
  135.         DIST_OS="hpux"
  136.         UNIX95=""
  137.         export UNIX95   
  138.         ;;
  139.     'darwin')
  140.         DIST_OS="macosx"
  141.         ;;
  142.     'unix_sv')
  143.         DIST_OS="unixware"
  144.         ;;
  145.     'os/390')
  146.         DIST_OS="zos"
  147.         ;;
  148. esac
  149.  
  150. # Resolve the architecture
  151. if [ "$DIST_OS" = "macosx" ]
  152. then
  153.     OS_VER=`sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'`
  154.     DIST_ARCH="universal"
  155.     if [[ "$OS_VER" < "10.5.0" ]]
  156.     then
  157.         DIST_BITS="32"
  158.     else
  159.         DIST_BITS="64"
  160.     fi
  161.     APP_PLIST_BASE=${PLIST_DOMAIN}.${APP_NAME}
  162.     APP_PLIST=${APP_PLIST_BASE}.plist
  163. else
  164.     DIST_ARCH=
  165.     DIST_ARCH=`uname -p 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
  166.     if [ "X$DIST_ARCH" = "X" ]
  167.     then
  168.         DIST_ARCH="unknown"
  169.     fi
  170.     if [ "$DIST_ARCH" = "unknown" ]
  171.     then
  172.         DIST_ARCH=`uname -m 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
  173.     fi
  174.     case "$DIST_ARCH" in
  175.         'athlon' | 'i386' | 'i486' | 'i586' | 'i686')
  176.             DIST_ARCH="x86"
  177.             if [ "${DIST_OS}" = "solaris" ] ; then
  178.                 DIST_BITS=`isainfo -b`
  179.             else
  180.                 DIST_BITS="32"
  181.             fi
  182.             ;;
  183.         'amd64' | 'x86_64')
  184.             DIST_ARCH="x86"
  185.             DIST_BITS="64"
  186.             ;;
  187.         'ia32')
  188.             DIST_ARCH="ia"
  189.             DIST_BITS="32"
  190.             ;;
  191.         'ia64' | 'ia64n' | 'ia64w')
  192.             DIST_ARCH="ia"
  193.             DIST_BITS="64"
  194.             ;;
  195.         'ip27')
  196.             DIST_ARCH="mips"
  197.             DIST_BITS="32"
  198.             ;;
  199.         'power' | 'powerpc' | 'power_pc' | 'ppc64')
  200.             if [ "${DIST_ARCH}" = "ppc64" ] ; then
  201.                 DIST_BITS="64"
  202.             else
  203.                 DIST_BITS="32"
  204.             fi
  205.             DIST_ARCH="ppc"
  206.             if [ "${DIST_OS}" = "aix" ] ; then
  207.                 if [ `getconf KERNEL_BITMODE` -eq 64 ]; then
  208.                     DIST_BITS="64"
  209.                 else
  210.                     DIST_BITS="32"
  211.                 fi
  212.             fi
  213.             ;;
  214.         'pa_risc' | 'pa-risc')
  215.             DIST_ARCH="parisc"
  216.             if [ `getconf KERNEL_BITS` -eq 64 ]; then
  217.                 DIST_BITS="64"
  218.             else
  219.                 DIST_BITS="32"
  220.             fi    
  221.             ;;
  222.         'sun4u' | 'sparcv9' | 'sparc')
  223.             DIST_ARCH="sparc"
  224.             DIST_BITS=`isainfo -b`
  225.             ;;
  226.         '9000/800' | '9000/785')
  227.             DIST_ARCH="parisc"
  228.             if [ `getconf KERNEL_BITS` -eq 64 ]; then
  229.                 DIST_BITS="64"
  230.             else
  231.                 DIST_BITS="32"
  232.             fi
  233.             ;;
  234.         '2097')
  235.             DIST_ARCH="390"
  236.             DIST_BITS="32"
  237.             ;;
  238.     esac
  239. fi
  240.  
  241. # OSX always places Java in the same location so we can reliably set JAVA_HOME
  242. if [ "$DIST_OS" = "macosx" ]
  243. then
  244.     if [ -z "$JAVA_HOME" ]; then
  245.         JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
  246.     fi
  247. fi
  248.  
  249. # Test Echo
  250. ECHOTEST=`echo -n "x"`
  251. if [ "$ECHOTEST" = "x" ]
  252. then
  253.     ECHOOPT="-n "
  254. else
  255.     ECHOOPT=""
  256. fi
  257.  
  258.  
  259. gettext() {
  260.     echo "$1"
  261. }
  262.  
  263. outputFile() {
  264.     if [ -f "$1" ]
  265.     then
  266.         eval echo  '  $1  Found but not executable.';
  267.     else
  268.         echo "  $1"
  269.     fi
  270. }
  271.  
  272. # Decide on the wrapper binary to use.
  273. # If the bits of the OS could be detected, we will try to look for the
  274. #  binary with the correct bits value.  If it doesn't exist, fall back
  275. #  and look for the 32-bit binary.  If that doesn't exist either then
  276. #  look for the default.
  277. WRAPPER_TEST_CMD=""
  278. if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" ]
  279. then
  280.     WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
  281.     if [ ! -x "$WRAPPER_TEST_CMD" ]
  282.     then
  283.         chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
  284.     fi
  285.     if [ -x "$WRAPPER_TEST_CMD" ]
  286.     then 
  287.         WRAPPER_CMD="$WRAPPER_TEST_CMD"
  288.     else
  289.         outputFile "$WRAPPER_TEST_CMD"
  290.         WRAPPER_TEST_CMD=""
  291.     fi
  292. fi
  293. if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" -a -z "$WRAPPER_TEST_CMD" ]
  294. then
  295.     WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
  296.     if [ ! -x "$WRAPPER_TEST_CMD" ]
  297.     then
  298.         chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
  299.     fi
  300.     if [ -x "$WRAPPER_TEST_CMD" ]
  301.     then 
  302.         WRAPPER_CMD="$WRAPPER_TEST_CMD"
  303.     else
  304.         outputFile "$WRAPPER_TEST_CMD"
  305.         WRAPPER_TEST_CMD=""
  306.     fi
  307. fi
  308. if [ -f "$WRAPPER_CMD" -a -z "$WRAPPER_TEST_CMD" ]
  309. then
  310.     WRAPPER_TEST_CMD="$WRAPPER_CMD"
  311.     if [ ! -x "$WRAPPER_TEST_CMD" ]
  312.     then
  313.         chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
  314.     fi
  315.     if [ -x "$WRAPPER_TEST_CMD" ]
  316.     then 
  317.         WRAPPER_CMD="$WRAPPER_TEST_CMD"
  318.     else
  319.         outputFile "$WRAPPER_TEST_CMD"
  320.         WRAPPER_TEST_CMD=""
  321.     fi
  322. fi
  323. if [ -z "$WRAPPER_TEST_CMD" ]
  324. then
  325.     eval echo  'Unable to locate any of the following binaries:'
  326.     outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
  327.     if [ ! "$DIST_BITS" = "32" ]
  328.     then
  329.         outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
  330.     fi
  331.     outputFile "$WRAPPER_CMD"
  332.  
  333.     exit 1
  334. fi
  335.  
  336.  
  337. # Build the nice clause
  338. if [ "X$PRIORITY" = "X" ]
  339. then
  340.     CMDNICE=""
  341. else
  342.     CMDNICE="nice -$PRIORITY"
  343. fi
  344.  
  345. # Build the anchor file clause.
  346. if [ "X$IGNORE_SIGNALS" = "X" ]
  347. then
  348.    ANCHORPROP=
  349.    IGNOREPROP=
  350. else
  351.    ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\"
  352.    IGNOREPROP=wrapper.ignore_signals=TRUE
  353. fi
  354.  
  355. # Build the status file clause.
  356. if [ "X$DETAIL_STATUS$WAIT_FOR_STARTED_STATUS" = "X" ]
  357. then
  358.    STATUSPROP=
  359. else
  360.    STATUSPROP="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
  361. fi
  362.  
  363. if [ ! -n "$WAIT_FOR_STARTED_STATUS" ]
  364. then
  365.     WAIT_FOR_STARTED_STATUS=true
  366. fi
  367.  
  368. if [ $WAIT_FOR_STARTED_STATUS = true ] ; then
  369.     DETAIL_STATUS=true
  370. fi
  371.  
  372.  
  373. # Build the lock file clause.  Only create a lock file if the lock directory exists on this platform.
  374. LOCKPROP=
  375. if [ -d $LOCKDIR ]
  376. then
  377.     if [ -w $LOCKDIR ]
  378.     then
  379.         LOCKPROP=wrapper.lockfile=\"$LOCKFILE\"
  380.     fi
  381. fi
  382.  
  383. checkUser() {
  384.     # $1 touchLock flag
  385.     # $2 command
  386.  
  387.     # Check the configured user.  If necessary rerun this script as the desired user.
  388.     if [ "X$RUN_AS_USER" != "X" ]
  389.     then
  390.         # Resolve the location of the 'id' command
  391.         IDEXE="/usr/xpg4/bin/id"
  392.         if [ ! -x "$IDEXE" ]
  393.         then
  394.             IDEXE="/usr/bin/id"
  395.             if [ ! -x "$IDEXE" ]
  396.             then
  397.                 eval echo  'Unable to locate "id".'
  398.                 eval echo  'Please report this message along with the location of the command on your system.'
  399.                 exit 1
  400.             fi
  401.         fi
  402.  
  403.         if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
  404.         then
  405.             # Already running as the configured user.  Avoid password prompts by not calling su.
  406.             RUN_AS_USER=""
  407.         fi
  408.     fi
  409.     if [ "X$RUN_AS_USER" != "X" ]
  410.     then
  411.         # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
  412.         # able to create the lock file.  The Wrapper will be able to update this file once it
  413.         # is created but will not be able to delete it on shutdown.  If $2 is defined then
  414.         # the lock file should be created for the current command
  415.         if [ "X$LOCKPROP" != "X" ]
  416.         then
  417.             if [ "X$1" != "X" ]
  418.             then
  419.                 # Resolve the primary group 
  420.                 RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
  421.                 if [ "X$RUN_AS_GROUP" = "X" ]
  422.                 then
  423.                     RUN_AS_GROUP=$RUN_AS_USER
  424.                 fi
  425.                 touch $LOCKFILE
  426.                 chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
  427.             fi
  428.         fi
  429.  
  430.         # Still want to change users, recurse.  This means that the user will only be
  431.         #  prompted for a password once. Variables shifted by 1
  432.         # 
  433.         # Use "runuser" if this exists.  runuser should be used on RedHat in preference to su.
  434.         #
  435.         if test -f "/sbin/runuser"
  436.         then
  437.             /sbin/runuser - $RUN_AS_USER -c "\"$REALPATH\" $2"
  438.         else
  439.             su - $RUN_AS_USER -c "\"$REALPATH\" $2"
  440.         fi
  441.  
  442.         # Now that we are the original user again, we may need to clean up the lock file.
  443.         if [ "X$LOCKPROP" != "X" ]
  444.         then
  445.             getpid
  446.             if [ "X$pid" = "X" ]
  447.             then
  448.                 # Wrapper is not running so make sure the lock file is deleted.
  449.                 if [ -f "$LOCKFILE" ]
  450.                 then
  451.                     rm "$LOCKFILE"
  452.                 fi
  453.             fi
  454.         fi
  455.  
  456.         exit 0
  457.     fi
  458. }
  459.  
  460. getpid() {
  461.     pid=""
  462.     if [ -f "$PIDFILE" ]
  463.     then
  464.         if [ -r "$PIDFILE" ]
  465.         then
  466.             pid=`cat "$PIDFILE"`
  467.             if [ "X$pid" != "X" ]
  468.             then
  469.                 # It is possible that 'a' process with the pid exists but that it is not the
  470.                 #  correct process.  This can happen in a number of cases, but the most
  471.                 #  common is during system startup after an unclean shutdown.
  472.                 # The ps statement below looks for the specific wrapper command running as
  473.                 #  the pid.  If it is not found then the pid file is considered to be stale.
  474.                 case "$DIST_OS" in
  475.                     'freebsd')
  476.                         pidtest=`$PSEXE -p $pid -o args | tail -1`
  477.                         if [ "X$pidtest" = "XCOMMAND" ]
  478.                         then 
  479.                             pidtest=""
  480.                         fi
  481.                         ;;
  482.                     'macosx')
  483.                         pidtest=`$PSEXE -ww -p $pid -o command | grep "$WRAPPER_CMD" | tail -1`
  484.                         ;;
  485.                     'solaris')
  486.                         if [ -f "/usr/bin/pargs" ]
  487.                         then
  488.                             pidtest=`pargs $pid | grep "$WRAPPER_CMD" | tail -1`
  489.                         else
  490.                             case "$PSEXE" in
  491.                             '/usr/ucb/ps')
  492.                                 pidtest=`$PSEXE -auxww  $pid | grep "$WRAPPER_CMD" | tail -1`
  493.                                 ;;
  494.                             '/usr/bin/ps')
  495.                                 TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
  496.                                 COUNT=`echo $TRUNCATED_CMD | wc -m`
  497.                                 COUNT=`echo ${COUNT}`
  498.                                 COUNT=`expr $COUNT - 1`
  499.                                 TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
  500.                                 pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1`
  501.                                 ;;
  502.                             '/bin/ps')
  503.                                 TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
  504.                                 COUNT=`echo $TRUNCATED_CMD | wc -m`
  505.                                 COUNT=`echo ${COUNT}`
  506.                                 COUNT=`expr $COUNT - 1`
  507.                                 TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
  508.                                 pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1`
  509.                                 ;;
  510.                             *)
  511.                                 echo "Unsupported ps command $PSEXE"
  512.                                 exit 1
  513.                                 ;;
  514.                             esac
  515.                         fi
  516.                         ;;
  517.                     'hpux')
  518.                         pidtest=`$PSEXE -p $pid -x -o args | grep "$WRAPPER_CMD" | tail -1`
  519.                         ;;
  520.                     *)
  521.                         pidtest=`$PSEXE -p $pid -o args | grep "$WRAPPER_CMD" | tail -1`
  522.                         ;;
  523.                 esac
  524.  
  525.                 if [ "X$pidtest" = "X" ]
  526.                 then
  527.                     # This is a stale pid file.
  528.                     rm -f "$PIDFILE"
  529.                     eval echo  'Removed stale pid file: $PIDFILE'
  530.                     pid=""
  531.                 fi
  532.             fi
  533.         else
  534.             eval echo  'Cannot read $PIDFILE.'
  535.             exit 1
  536.         fi
  537.     fi
  538. }
  539.  
  540. getstatus() {
  541.     STATUS=
  542.     if [ -f "$STATUSFILE" ]
  543.     then
  544.         if [ -r "$STATUSFILE" ]
  545.         then
  546.             STATUS=`cat "$STATUSFILE"`
  547.         fi
  548.     fi
  549.     if [ "X$STATUS" = "X" ]
  550.     then
  551.         STATUS="Unknown"
  552.     fi
  553.     
  554.     JAVASTATUS=
  555.     if [ -f "$JAVASTATUSFILE" ]
  556.     then
  557.         if [ -r "$JAVASTATUSFILE" ]
  558.         then
  559.             JAVASTATUS=`cat "$JAVASTATUSFILE"`
  560.         fi
  561.     fi
  562.     if [ "X$JAVASTATUS" = "X" ]
  563.     then
  564.         JAVASTATUS="Unknown"
  565.     fi
  566. }
  567.  
  568. testpid() {
  569.     case "$DIST_OS" in
  570.      'solaris')
  571.         case "$PSEXE" in
  572.         '/usr/ucb/ps')
  573.             pid=`$PSEXE  $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  574.             ;;
  575.         '/usr/bin/ps')
  576.             pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  577.             ;;
  578.         '/bin/ps')
  579.             pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
  580.             ;;
  581.         *)
  582.             echo "Unsupported ps command $PSEXE"
  583.             exit 1
  584.             ;;
  585.         esac
  586.         ;;
  587.     *)
  588.         pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev/null
  589.         ;;
  590.     esac
  591.     if [ "X$pid" = "X" ]
  592.     then
  593.         # Process is gone so remove the pid file.
  594.         rm -f "$PIDFILE"
  595.         pid=""
  596.     fi
  597. }
  598.  
  599. launchdtrap() {
  600.     stopit
  601.     exit 
  602. }
  603.  
  604. waitforwrapperstop() {
  605.     getpid
  606.     while [ "X$pid" != "X" ] ; do
  607.         sleep 1
  608.         getpid
  609.     done
  610. }
  611.  
  612. launchdinternal() {
  613.     getpid
  614.     trap launchdtrap TERM 
  615.     if [ "X$pid" = "X" ]
  616.     then 
  617.         # The string passed to eval must handles spaces in paths correctly.
  618.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $LOCKPROP"
  619.         eval $COMMAND_LINE
  620.     else
  621.         eval echo  '$APP_LONG_NAME is already running.'
  622.         exit 1
  623.     fi
  624.     # launchd expects that this script stay up and running so we need to do our own monitoring of the Wrapper process.
  625.     if [ $WAIT_FOR_STARTED_STATUS = true ]
  626.     then
  627.         waitforwrapperstop
  628.     fi
  629. }
  630.  
  631. console() {
  632.     eval echo  'Running $APP_LONG_NAME...'
  633.     getpid
  634.     if [ "X$pid" = "X" ]
  635.     then
  636.         trap '' 3
  637.         # The string passed to eval must handles spaces in paths correctly.
  638.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" $ANCHORPROP $STATUSPROP $LOCKPROP"
  639.         eval $COMMAND_LINE
  640.     else
  641.         eval echo  '$APP_LONG_NAME is already running.'
  642.         exit 1
  643.     fi
  644. }
  645.  
  646. waitforjavastartup() {
  647.     getstatus
  648.     eval echo $ECHOOPT `gettext 'Waiting for $APP_LONG_NAME...'`
  649.     
  650.     # Wait until the timeout or we have something besides Unknown.
  651.     counter=15
  652.     while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
  653.         echo $ECHOOPT"."
  654.         sleep 1
  655.         getstatus
  656.         counter=`expr $counter - 1`
  657.     done
  658.     
  659.     if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then 
  660.         counter=$WAIT_FOR_STARTED_TIMEOUT
  661.     else
  662.         counter=120
  663.     fi
  664.     while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
  665.         echo $ECHOOPT"."
  666.         sleep 1
  667.         getstatus
  668.         counter=`expr $counter - 1`
  669.     done
  670.     if [ "X$ECHOOPT" != "X" ] ; then
  671.         echo ""
  672.     fi
  673. }
  674.  
  675. startwait() {
  676.     if [ $WAIT_FOR_STARTED_STATUS = true ]
  677.     then
  678.         waitforjavastartup
  679.     fi
  680.     # Sleep for a few seconds to allow for intialization if required 
  681.     #  then test to make sure we're still running.
  682.     #
  683.     i=0
  684.     while [ $i -lt $WAIT_AFTER_STARTUP ]
  685.     do
  686.         sleep 1
  687.         echo $ECHOOPT"."
  688.         i=`expr $i + 1`
  689.     done
  690.     if [ $WAIT_AFTER_STARTUP -gt 0 -o $WAIT_FOR_STARTED_STATUS = true ]
  691.     then
  692.         getpid
  693.         if [ "X$pid" = "X" ]
  694.         then
  695.             eval echo  ' WARNING: $APP_LONG_NAME may have failed to start.'
  696.             exit 1
  697.         else
  698.             eval echo  ' running: PID:$pid'
  699.         fi
  700.     else 
  701.         echo ""
  702.     fi
  703. }
  704.  
  705. macosxstart() {
  706.     # The daemon has been installed.
  707.     eval echo  'Starting $APP_LONG_NAME.  Detected Mac OSX and installed launchd daemon.'
  708.     if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then       
  709.         eval echo  'Must be root to perform this action.'
  710.         exit 1
  711.     fi
  712.     
  713.     getpid
  714.     if [ "X$pid" != "X" ] ; then
  715.         eval echo  '$APP_LONG_NAME is already running.'
  716.         exit 1
  717.     fi
  718.     
  719.     # If the daemon was just installed, it may not be loaded.
  720.     LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
  721.     if [ "X${LOADED_PLIST}" = "X" ] ; then
  722.         launchctl load /Library/LaunchDaemons/${APP_PLIST}
  723.     fi
  724.     # If launchd is set to run the daemon already at Load, we don't need to call start
  725.     getpid
  726.     if [ "X$pid" == "X" ] ; then
  727.         launchctl start ${APP_PLIST_BASE}
  728.     fi
  729.     
  730.     startwait
  731. }
  732.  
  733. start() {
  734.     eval echo  'Starting $APP_LONG_NAME...'
  735.     getpid
  736.     if [ "X$pid" = "X" ]
  737.     then
  738.         # The string passed to eval must handles spaces in paths correctly.
  739.         COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $LOCKPROP"
  740.         eval $COMMAND_LINE
  741.     else
  742.         eval echo  '$APP_LONG_NAME is already running.'
  743.         exit 1
  744.     fi
  745.     
  746.     startwait
  747. }
  748.  
  749. stopit() {
  750.     # $1 exit if down flag
  751.     
  752.     eval echo  'Stopping $APP_LONG_NAME...'
  753.     getpid
  754.     if [ "X$pid" = "X" ]
  755.     then
  756.         eval echo  '$APP_LONG_NAME was not running.'
  757.         if [ "X$1" = "X1" ]
  758.         then
  759.             exit 1
  760.         fi
  761.     else
  762.         if [ "X$IGNORE_SIGNALS" = "X" ]
  763.         then
  764.             # Running so try to stop it.
  765.             kill $pid
  766.             if [ $? -ne 0 ]
  767.             then
  768.                 # An explanation for the failure should have been given
  769.                 eval echo  'Unable to stop $APP_LONG_NAME.'
  770.                 exit 1
  771.             fi
  772.         else
  773.             rm -f "$ANCHORFILE"
  774.             if [ -f "$ANCHORFILE" ]
  775.             then
  776.                 # An explanation for the failure should have been given
  777.                 eval echo  'Unable to stop $APP_LONG_NAME.'
  778.                 exit 1
  779.             fi
  780.         fi
  781.  
  782.         # We can not predict how long it will take for the wrapper to
  783.         #  actually stop as it depends on settings in wrapper.conf.
  784.         #  Loop until it does.
  785.         savepid=$pid
  786.         CNT=0
  787.         TOTCNT=0
  788.         while [ "X$pid" != "X" ]
  789.         do
  790.             # Show a waiting message every 5 seconds.
  791.             if [ "$CNT" -lt "5" ]
  792.             then
  793.                 CNT=`expr $CNT + 1`
  794.             else
  795.                 eval echo  'Waiting for $APP_LONG_NAME to exit...'
  796.                 CNT=0
  797.             fi
  798.             TOTCNT=`expr $TOTCNT + 1`
  799.  
  800.             sleep 1
  801.  
  802.             testpid
  803.         done
  804.  
  805.         pid=$savepid
  806.         testpid
  807.         if [ "X$pid" != "X" ]
  808.         then
  809.             eval echo  'Failed to stop $APP_LONG_NAME.'
  810.             exit 1
  811.         else
  812.             eval echo  'Stopped $APP_LONG_NAME.'
  813.         fi
  814.     fi
  815. }
  816.  
  817. status() {
  818.     getpid
  819.     if [ "X$pid" = "X" ]
  820.     then
  821.         eval echo  '$APP_LONG_NAME is not running.'
  822.         exit 1
  823.     else
  824.         if [ "X$DETAIL_STATUS" = "X" ]
  825.         then
  826.             eval echo  '$APP_LONG_NAME is running: PID:$pid'
  827.         else
  828.             getstatus
  829.             eval echo  '$APP_LONG_NAME is running: PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS'
  830.         fi
  831.         exit 0
  832.     fi
  833. }
  834.  
  835. installdaemon() {
  836.     if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then       
  837.         eval echo  'Must be root to perform this action.'
  838.         exit 1
  839.     else
  840.         APP_NAME_LOWER=`echo "$APP_NAME" | tr [A-Z] [a-z]`
  841.         if [ "$DIST_OS" = "solaris" ] ; then
  842.             eval echo  'Detected Solaris:'
  843.             if [ -f /etc/init.d/$APP_NAME ] ; then
  844.                 eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  845.                 exit 1
  846.             else
  847.                 eval echo  ' Installing the $APP_LONG_NAME daemon..'
  848.                 ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  849.                 ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
  850.                 ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
  851.             fi
  852.         elif [ "$DIST_OS" = "linux" ] ; then
  853.             if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ]  ; then
  854.                 eval echo  'Detected RHEL or Fedora:'                  
  855.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  856.                     eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  857.                     exit 1
  858.                 else
  859.                     eval echo  ' Installing the $APP_LONG_NAME daemon..'
  860.                     ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  861.                     /sbin/chkconfig --add "$APP_NAME"
  862.                     /sbin/chkconfig "$APP_NAME" on
  863.                 fi
  864.             elif [ -f /etc/SuSE-release ] ; then
  865.                 eval echo  'Detected SuSE or SLES:'
  866.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  867.                     eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  868.                     exit 1
  869.                 else
  870.                     eval echo  ' Installing the $APP_LONG_NAME daemon..'
  871.                     ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  872.                     insserv "/etc/init.d/$APP_NAME"
  873.                 fi
  874.             elif [ -f /etc/lsb-release ] ; then
  875.                 eval echo  'Detected Ubuntu:'
  876.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  877.                     eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  878.                     exit 1
  879.                 else
  880.                     eval echo  ' Installing the $APP_LONG_NAME daemon..'
  881.                     ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
  882.                     update-rc.d "$APP_NAME" defaults
  883.                 fi
  884.             else
  885.                 eval echo  'Detected Linux:'
  886.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  887.                     eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  888.                     exit 1
  889.                 else
  890.                     eval echo  ' Installing the $APP_LONG_NAME daemon..'
  891.                     ln -s "$REALPATH" /etc/init.d/$APP_NAME
  892.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
  893.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
  894.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
  895.                     ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/K20$APP_NAME_LOWER"
  896.                 fi
  897.             fi
  898.         elif [ "$DIST_OS" = "hpux" ] ; then     
  899.             eval echo  'Detected HP-UX:'          
  900.             if [ -f "/sbin/init.d/$APP_NAME" ] ; then
  901.                 eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  902.                 exit 1
  903.             else
  904.                 eval echo  ' Installing the $APP_LONG_NAME daemon..'
  905.                 ln -s "$REALPATH" "/sbin/init.d/$APP_NAME"
  906.                 ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/K20$APP_NAME_LOWER"
  907.                 ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/S20$APP_NAME_LOWER"
  908.             fi
  909.         elif [ "$DIST_OS" = "aix" ] ; then
  910.             eval echo  'Detected AIX:'
  911.             if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
  912.                 eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  913.                 exit 1
  914.             else 
  915.                 eval echo  ' Installing the $APP_LONG_NAME daemon..'
  916.                 ln -s "$REALPATH" /etc/rc.d/init.d/$APP_NAME
  917.                 ln -s "/etc/rc.d/init.d/$APP_NAME" "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER"
  918.                 ln -s "/etc/rc.d/init.d/$APP_NAME" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER"
  919.             fi
  920.         elif [ "$DIST_OS" = "freebsd" ] ; then
  921.             eval echo  'Detected FreeBSD:'                
  922.             if [ -f "/etc/rc.d/$APP_NAME" ] ; then
  923.                 eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  924.                 exit 1
  925.             else
  926.                 eval echo  ' Installing the $APP_LONG_NAME daemon..'
  927.                 sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
  928.                 if [ -f "${REALDIR}/${APP_NAME}.install" ] ; then
  929.                     ln -s "${REALDIR}/${APP_NAME}.install" "/etc/rc.d/$APP_NAME"
  930.                 else
  931.                     echo '#!/bin/sh' > "/etc/rc.d/$APP_NAME"
  932.                     echo "#" >> "/etc/rc.d/$APP_NAME"
  933.                     echo "# PROVIDE: $APP_NAME" >> "/etc/rc.d/$APP_NAME"
  934.                     echo "# REQUIRE: NETWORKING" >> "/etc/rc.d/$APP_NAME"
  935.                     echo "# KEYWORD: shutdown" >> "/etc/rc.d/$APP_NAME"
  936.                     echo ". /etc/rc.subr" >> "/etc/rc.d/$APP_NAME"
  937.                     echo "name=\"$APP_NAME\"" >> "/etc/rc.d/$APP_NAME"
  938.                     echo "rcvar=\`set_rcvar\`" >> "/etc/rc.d/$APP_NAME"
  939.                     echo "command=\"${REALDIR}/${APP_NAME}\"" >> "/etc/rc.d/$APP_NAME"
  940.                     echo 'start_cmd="${name}_start"' >> "/etc/rc.d/$APP_NAME"
  941.                     echo 'load_rc_config $name' >> "/etc/rc.d/$APP_NAME"
  942.                     echo 'status_cmd="${name}_status"' >> "/etc/rc.d/$APP_NAME"
  943.                     echo 'stop_cmd="${name}_stop"' >> "/etc/rc.d/$APP_NAME"
  944.                     echo "${APP_NAME}_status() {" >> "/etc/rc.d/$APP_NAME"
  945.                     echo '${command} status' >> "/etc/rc.d/$APP_NAME"
  946.                     echo '}' >> "/etc/rc.d/$APP_NAME"
  947.                     echo "${APP_NAME}_stop() {" >> "/etc/rc.d/$APP_NAME"
  948.                     echo '${command} stop' >> "/etc/rc.d/$APP_NAME"
  949.                     echo '}' >> "/etc/rc.d/$APP_NAME"
  950.                     echo "${APP_NAME}_start() {" >> "/etc/rc.d/$APP_NAME"
  951.                     echo '${command} start' >> "/etc/rc.d/$APP_NAME"
  952.                     echo '}' >> "/etc/rc.d/$APP_NAME"
  953.                     echo 'run_rc_command "$1"' >> "/etc/rc.d/$APP_NAME"
  954.                 fi
  955.                 echo "${APP_NAME}_enable=\"YES\"" >> /etc/rc.conf
  956.                 chmod 555 "/etc/rc.d/$APP_NAME"
  957.             fi
  958.         elif [ "$DIST_OS" = "macosx" ] ; then
  959.             eval echo  'Detected Mac OSX:'
  960.             if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
  961.                 eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  962.                 exit 1
  963.             else
  964.                 eval echo  ' Installing the $APP_LONG_NAME daemon..'
  965.                 if [ -f "${REALDIR}/${APP_PLIST}" ] ; then
  966.                     ln -s "${REALDIR}/${APP_PLIST}" "/Library/LaunchDaemons/${APP_PLIST}"
  967.                 else
  968.                     echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "/Library/LaunchDaemons/${APP_PLIST}"
  969.                     echo "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" >> "/Library/LaunchDaemons/${APP_PLIST}"
  970.                     echo "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
  971.                     echo "<plist version=\"1.0\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
  972.                     echo "    <dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  973.                     echo "        <key>Label</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  974.                     echo "        <string>${APP_PLIST_BASE}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  975.                     echo "        <key>ProgramArguments</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  976.                     echo "        <array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  977.                     echo "            <string>${REALDIR}/${APP_NAME}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  978.                     echo "            <string>launchdinternal</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  979.                     echo "        </array>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  980.                     echo "        <key>OnDemand</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  981.                     echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  982.                     echo "        <key>RunAtLoad</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  983.                     echo "        <true/>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  984.                     if [ "X$RUN_AS_USER" != "X" ] ; then
  985.                         echo "        <key>UserName</key>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  986.                         echo "        <string>${RUN_AS_USER}</string>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  987.                     fi
  988.                     echo "    </dict>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  989.                     echo "</plist>" >> "/Library/LaunchDaemons/${APP_PLIST}"
  990.                 fi
  991.                 chmod 555 "/Library/LaunchDaemons/${APP_PLIST}"
  992.             fi
  993.         elif [ "$DIST_OS" = "zos" ] ; then
  994.             eval echo  'Detected z/OS:'
  995.             if [ -f /etc/rc.bak ] ; then
  996.                 eval echo  ' The $APP_LONG_NAME daemon is already installed.'
  997.                 exit 1
  998.             else
  999.                 eval echo  ' Installing the $APP_LONG_NAME daemon..'
  1000.                 cp /etc/rc /etc/rc.bak
  1001.                 sed  "s:echo /etc/rc script executed, \`date\`::g" /etc/rc.bak > /etc/rc
  1002.                 echo "_BPX_JOBNAME='${APP_NAME}' \"${REALDIR}/${APP_NAME}\" start" >>/etc/rc
  1003.                 echo '/etc/rc script executed, `date`' >>/etc/rc
  1004.             fi
  1005.         else
  1006.             eval echo  'Install not currently supported for $DIST_OS'
  1007.             exit 1
  1008.         fi
  1009.     fi
  1010. }
  1011.  
  1012. removedaemon() {
  1013.     if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then       
  1014.         eval echo  'Must be root to perform this action.'
  1015.         exit 1
  1016.     else
  1017.         stopit "0"
  1018.         APP_NAME_LOWER=`echo "$APP_NAME" | tr [A-Z] [a-z]`
  1019.         if [ "$DIST_OS" = "solaris" ] ; then
  1020.             eval echo  'Detected Solaris:'
  1021.             if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1022.                 eval echo  ' Removing $APP_LONG_NAME daemon...'
  1023.                 for i in "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME"
  1024.                 do
  1025.                     rm -f $i
  1026.                 done
  1027.             else
  1028.                 eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1029.                 exit 1
  1030.             fi
  1031.         elif [ "$DIST_OS" = "linux" ] ; then
  1032.             if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
  1033.                 eval echo  'Detected RHEL or Fedora:'
  1034.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1035.                     eval echo  ' Removing $APP_LONG_NAME daemon...'
  1036.                     /sbin/chkconfig "$APP_NAME" off
  1037.                     /sbin/chkconfig --del "$APP_NAME"
  1038.                     rm -f "/etc/init.d/$APP_NAME"
  1039.                 else
  1040.                     eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1041.                     exit 1
  1042.                 fi
  1043.             elif [ -f /etc/SuSE-release ] ; then
  1044.                 eval echo  'Detected SuSE or SLES:'
  1045.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1046.                     eval echo  ' Removing $APP_LONG_NAME daemon...'
  1047.                     insserv -r "/etc/init.d/$APP_NAME"
  1048.                     rm -f "/etc/init.d/$APP_NAME"
  1049.                 else
  1050.                     eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1051.                     exit 1
  1052.                 fi
  1053.             elif [ -f /etc/lsb-release ] ; then
  1054.                 eval echo  'Detected Ubuntu:'
  1055.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1056.                     eval echo  ' Removing $APP_LONG_NAME daemon...'
  1057.                     update-rc.d -f "$APP_NAME" remove
  1058.                     rm -f "/etc/init.d/$APP_NAME"
  1059.                 else
  1060.                     eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1061.                     exit 1
  1062.                 fi
  1063.             else
  1064.                 eval echo  'Detected Linux:'
  1065.                 if [ -f "/etc/init.d/$APP_NAME" ] ; then
  1066.                     eval echo  ' Removing $APP_LONG_NAME daemon...'
  1067.                     for i in "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/rc5.d/K20$APP_NAME_LOWER" "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
  1068.                     do
  1069.                         rm -f $i
  1070.                     done
  1071.                 else
  1072.                     eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1073.                     exit 1
  1074.                 fi
  1075.             fi
  1076.         elif [ "$DIST_OS" = "hpux" ] ; then
  1077.             eval echo  'Detected HP-UX:'
  1078.             if [ -f "/sbin/init.d/$APP_NAME" ] ; then
  1079.                 eval echo  ' Removing $APP_LONG_NAME daemon...'
  1080.                 for i in "/sbin/rc3.d/K20$APP_NAME_LOWER" "/sbin/rc3.d/S20$APP_NAME_LOWER" "/sbin/init.d/$APP_NAME"
  1081.                 do
  1082.                     rm -f $i
  1083.                 done
  1084.             else
  1085.                 eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1086.                 exit 1
  1087.             fi
  1088.         elif [ "$DIST_OS" = "aix" ] ; then
  1089.             eval echo  'Detected AIX:'
  1090.             if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
  1091.                 eval echo  ' Removing $APP_LONG_NAME daemon...'
  1092.                 for i in "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER" "/etc/rc.d/init.d/$APP_NAME"
  1093.                 do
  1094.                     rm -f $i
  1095.                 done
  1096.             else
  1097.                 eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1098.                 exit 1
  1099.             fi
  1100.         elif [ "$DIST_OS" = "freebsd" ] ; then
  1101.             eval echo  'Detected FreeBSD:'
  1102.             if [ -f "/etc/rc.d/$APP_NAME" ] ; then
  1103.                 eval echo  ' Removing $APP_LONG_NAME daemon...'
  1104.                 for i in "/etc/rc.d/$APP_NAME"
  1105.                 do
  1106.                     rm -f $i
  1107.                 done
  1108.                 sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
  1109.             else
  1110.                 eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1111.                 exit 1
  1112.             fi
  1113.         elif [ "$DIST_OS" = "macosx" ] ; then
  1114.             eval echo  'Detected Mac OSX:'
  1115.             if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
  1116.                 eval echo  ' Removing $APP_LONG_NAME daemon...'
  1117.                 # Make sure the plist is installed
  1118.                 LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
  1119.                 if [ "X${LOADED_PLIST}" != "X" ] ; then
  1120.                     launchctl unload "/Library/LaunchDaemons/${APP_PLIST}"
  1121.                 fi
  1122.                 rm -f "/Library/LaunchDaemons/${APP_PLIST}"
  1123.             else
  1124.                 eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1125.                 exit 1
  1126.             fi
  1127.         elif [ "$DIST_OS" = "zos" ] ; then
  1128.             eval echo  'Detected z/OS:'
  1129.             if [ -f /etc/rc.bak ] ; then
  1130.                 eval echo  ' Removing $APP_LONG_NAME daemon...'
  1131.                 cp /etc/rc /etc/rc.bak
  1132.                 sed  "s/_BPX_JOBNAME=\'APP_NAME\'.*//g" /etc/rc.bak > /etc/rc
  1133.                 rm /etc/rc.bak
  1134.             else
  1135.                 eval echo  ' The $APP_LONG_NAME daemon is not currently installed.'
  1136.                 exit 1
  1137.             fi
  1138.         else
  1139.             eval echo  'Remove not currently supported for $DIST_OS'
  1140.             exit 1
  1141.         fi
  1142.     fi
  1143. }
  1144.  
  1145. dump() {
  1146.     eval echo  'Dumping $APP_LONG_NAME...'
  1147.     getpid
  1148.     if [ "X$pid" = "X" ]
  1149.     then
  1150.         eval echo  '$APP_LONG_NAME was not running.'
  1151.     else
  1152.         kill -3 $pid
  1153.  
  1154.         if [ $? -ne 0 ]
  1155.         then
  1156.             eval echo  'Failed to dump $APP_LONG_NAME.'
  1157.             exit 1
  1158.         else
  1159.             eval echo  'Dumped $APP_LONG_NAME.'
  1160.         fi
  1161.     fi
  1162. }
  1163.  
  1164. # Used by HP-UX init scripts.
  1165. startmsg() {
  1166.     getpid
  1167.     if [ "X$pid" = "X" ]
  1168.     then
  1169.         eval echo  'Starting $APP_LONG_NAME...  Wrapper:Stopped'
  1170.     else
  1171.         if [ "X$DETAIL_STATUS" = "X" ]
  1172.         then
  1173.             eval echo  'Starting $APP_LONG_NAME...  Wrapper:Running'
  1174.         else
  1175.             getstatus
  1176.             eval echo  'Starting $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS'
  1177.         fi
  1178.     fi
  1179. }
  1180.  
  1181. # Used by HP-UX init scripts.
  1182. stopmsg() {
  1183.     getpid
  1184.     if [ "X$pid" = "X" ]
  1185.     then
  1186.         eval echo  'Stopping $APP_LONG_NAME...  Wrapper:Stopped'
  1187.     else
  1188.         if [ "X$DETAIL_STATUS" = "X" ]
  1189.         then
  1190.             eval echo  'Stopping $APP_LONG_NAME...  Wrapper:Running'
  1191.         else
  1192.             getstatus
  1193.             eval echo  'Stopping $APP_LONG_NAME...  Wrapper:$STATUS, Java:$JAVASTATUS'
  1194.         fi
  1195.     fi
  1196. }
  1197.  
  1198. case "$1" in
  1199.  
  1200.     'console')
  1201.         checkUser touchlock $1
  1202.         console
  1203.         ;;
  1204.  
  1205.     'start')
  1206.         if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
  1207.             macosxstart
  1208.         else
  1209.             checkUser touchlock $1
  1210.             start
  1211.         fi
  1212.         ;;
  1213.  
  1214.     'stop')
  1215.         checkUser "" $1
  1216.         stopit "0"
  1217.         ;;
  1218.  
  1219.     'restart')
  1220.         checkUser touchlock $1
  1221.         stopit "0"
  1222.         start
  1223.         ;;
  1224.  
  1225.     'condrestart')
  1226.         checkUser touchlock $1
  1227.         stopit "1"
  1228.         start
  1229.         ;;
  1230.  
  1231.     'status')
  1232.         checkUser "" $1
  1233.         status
  1234.         ;;
  1235.  
  1236.     'install')
  1237.         installdaemon
  1238.         ;;
  1239.  
  1240.     'remove')
  1241.         removedaemon
  1242.         ;;
  1243.  
  1244.     'dump')
  1245.         checkUser "" $1
  1246.         dump
  1247.         ;;
  1248.  
  1249.     'start_msg')
  1250.         # Internal command called by launchd on HP-UX.
  1251.         checkUser "" $1
  1252.         startmsg
  1253.         ;;
  1254.  
  1255.     'stop_msg')
  1256.         # Internal command called by launchd on HP-UX.
  1257.         checkUser "" $1
  1258.         stopmsg
  1259.         ;;
  1260.  
  1261.     'launchdinternal')
  1262.         # Internal command called by launchd on Max OSX.
  1263.         # We do not want to call checkUser here as it is handled in the launchd plist file.  Doing it here would confuse launchd.
  1264.         launchdinternal
  1265.         ;;
  1266.  
  1267.     *)
  1268.         eval MSG=`gettext 'Usage: '`
  1269.         echo "${MSG} $0 { console | start | stop | restart | condrestart | status | install | remove | dump }"
  1270.         exit 1
  1271.         ;;
  1272. esac
  1273.  
  1274. exit 0
  1275.